package com.lianyi.login.mvp.presenter;

import android.app.Application;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;

import javax.inject.Inject;

import com.lianyi.commonsdk.util.GsonUtil;
import com.lianyi.commonsdk.util.LogUtil;
import com.lianyi.login.mvp.contract.DoctorListContract;
import com.lianyi.login.mvp.model.entity.DoctorListBean;
import com.lianyi.login.mvp.ui.activity.DoctorListActivity;

import java.util.List;


@ActivityScope
public class DoctorListPresenter extends BasePresenter<DoctorListContract.Model, DoctorListContract.View> {
    private RxErrorHandler mErrorHandler;
    private Application mApplication;
    private ImageLoader mImageLoader;
    private AppManager mAppManager;
    @Inject
    List<DoctorListBean> mUsers;
    @Inject
    RecyclerView.Adapter mAdapter;

    @Inject
    public DoctorListPresenter(DoctorListContract.Model model, DoctorListContract.View rootView
            , RxErrorHandler handler, Application application
            , ImageLoader imageLoader, AppManager appManager) {
        super(model, rootView);
        this.mErrorHandler = handler;
        this.mApplication = application;
        this.mImageLoader = imageLoader;
        this.mAppManager = appManager;
    }

    public void getDoctorList(Bundle bundle) {
        if (bundle != null) {
            String mDate = bundle.getString(DoctorListActivity.DOCTOR_LIST_ALL);
            List<DoctorListBean> list = GsonUtil.GsonToList(mDate, DoctorListBean.class);
            for (int i = 0; i < list.size(); i++) {
                LogUtil.e("医生姓名:", list.get(i).getName() + "==");
                DoctorListBean doctorListBean = list.get(i);
                mUsers.add(doctorListBean);
            }
//            mAdapter.notifyDataSetChanged();
        } else {
            LogUtil.e("getDoctorList bundle is null", "getDoctorList bundle is null");
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
    }

}
